package util;

import com.thoughtworks.qdox.JavaProjectBuilder;
import com.thoughtworks.qdox.model.JavaClass;
import com.thoughtworks.qdox.model.JavaMethod;

import java.io.*;
import java.lang.reflect.Method;

/**
 * 这是一个测试
 * https://gitcode.com/gh_mirrors/qd/qdox/?utm_source=artical_gitcode&index=bottom&type=card&&isLogin=1#qdox-%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97
 */
public class JavaDocQdox {
    /**
     * 测试方法
     * @param args
     */
    public static void main(String[] args) throws IOException {

        Class<?> clazz = DocQdoxTestClass.class;
        String path = clazz.getResource("").getPath();
        File file = new File(path);
        String absolutePath = file.getPath();
        System.out.println("======>"+absolutePath);

        JavaProjectBuilder builder = new JavaProjectBuilder();
     //   builder.addSource(new FileReader("DocQdoxTestClass.java"));

        // 逐个文件读取源代码。
      //  builder.addSource(new FileReader("MyFile.java"));

// 从其他类型的流读取。
     //   builder.addSource(new StringReader("package test; public class Hello {}"));

// 添加指定目录下的所有.java文件（递归读取）。
        builder.addSourceTree(new File(absolutePath));

        JavaClass javaClass = builder.getClassByName("util.DocQdoxTestClass");
        if (javaClass!= null) {
            String classComment = javaClass.getComment();
            System.out.println("Class Comment: " + classComment);

            for (JavaMethod method : javaClass.getMethods()) {
                String methodComment = method.getComment();
                System.out.println("Method Comment: " + methodComment);
            }
        }
    }



}
